package com.violet.domain.result;

import com.violet.domain.emuns.Code;
import lombok.Data;

import java.io.Serializable;

@Data
public class Result<E> implements Serializable {
    private E data;
    private String message;
    private int code;

    protected Result() {}

    protected Result(E data, String message, int code) {
        this.data = data;
        this.message = message;
        this.code = code;
    }

// ===================================== success =====================================

    public static <E> Result<E> success() {
        return new Result<>(null, Code.SUCCESS.message, Code.SUCCESS.code);
    }

    public static <E> Result<E> success(E data, String message) {
        return new Result<>(data, message, Code.SUCCESS.code);
    }

// ===================================== error =====================================

    public static <E> Result<E> error(E data, String message) {
        return new Result<>(data, message, Code.FAIL.code);
    }

    public static <E> Result<E> error(String message) {
        return new Result<>(null, message, Code.FAIL.code);
    }

    public static <E> Result<E> error() {
        return new Result<>(null, Code.FAIL.message, Code.FAIL.code);
    }

}
